<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="nav">
      <el-breadcrumb-item to="/"><strong>首页</strong></el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单详情 </el-breadcrumb-item>
    </el-breadcrumb>
    <!--面包屑-->
    <el-card class="box-card">
      <div class="header">
        <el-input
          placeholder="请输入内容"
          v-model.trim="value"
          class="input-with-select"
          clearable
          @clear="getordersList"
        >
          <el-button
            slot="append"
            @click="btn"
            icon="el-icon-search"
          ></el-button>
        </el-input>
      </div>
      <!--表格-->
      <el-table
        class="table"
        border
        :data="list"
        style="width: 100%"
        max-height="500"
      >
        <el-table-column align="center" label="" width="50">
          <template slot-scope="{ $index }">
            {{ obj.pagesize * (obj.pagenum - 1) + $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="{ row }">
            <span
              :class="[
                row.pay_status == '0'
                  ? 'el-tag el-tag--danger el-tag--light'
                  : 'el-tag el-tag--success el-tag--light',
              ]"
              v-html="row.pay_status == '0' ? '未付款' : '已付款'"
            ></span>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column
          :formatter="formatCreateTime"
          prop="create_time"
          label="下单时间"
        >
        </el-table-column>
        <el-table-column label="操作">
          <!-- slot-scope="{ row }" -->
          <template slot-scope="{ row }">
            <div class="actions">
              <el-button @click="edit(row.order_id)" type="primary">
                <i class="el-icon-edit"></i
              ></el-button>
              <el-button type="success" @click="getkuaidi(row.order_id)">
                <i class="el-icon-location"></i
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="Number(obj.pagenum)"
        :page-sizes="listarr"
        :page-size="Number(obj.pagesize)"
        layout="total, sizes, prev, pager, next, jumper"
        :total="Number(total)"
        style="margin-top: 20px"
      >
      </el-pagination>
      <!--物流进度对话框-->
      <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
        <!-- 时间线 -->
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in kuaidi"
            :key="index"
            :timestamp="item.time"
          >
            {{ item.context }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>

      <!-- 修改地址的对话框 -->
      <el-dialog title="修改地址" :visible.sync="addressVisible" width="50%">
        <el-form
          :model="addressForm"
          :rules="rules"
          ref="addressFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-input v-model="addressForm.address1"></el-input>
            <!-- <el-cascader v-model="addressForm.address1"></el-cascader> -->
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="addressForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addressVisible = false">取 消</el-button>
          <el-button type="primary" @click="queren">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import { ordersApi, kuaidiApi } from '@/api/orders'
export default {
  name: '',
  data () {
    return {
      list: [],
      obj: {
        query: 'itcast-g7kmck725jaujgdts  ',
        pagenum: '1',
        pagesize: '10'
      },
      addressForm: {
        address1: '',
        address2: ''
      },
      listarr: [1, 2, 5, 10, 30],
      total: '',
      // 物流对话框
      progressVisible: false,
      kuaidi: [],
      // 地址对话框
      addressVisible: false,
      rules: {
        address1: [{ required: true, message: '请输入地址', trigger: 'blur' }],
        address2: [{ required: true, message: '请输入地址', trigger: 'blur' }]
      },
      value: ''
    }
  },
  created () {
    this.getordersList()
    console.log(this.list)
  },
  computed: {
  },
  methods: {
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.obj.pagesize = val
      this.getordersList()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.obj.pagenum = val
      this.getordersList()
    },
    /** ******************----------------**********************/
    formatCreateTime (row, column, cellValue) {
      const timestamp = cellValue // 假设 `create_time` 是时间戳
      const date = new Date(timestamp)
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2)
      const day = ('0' + date.getDate()).slice(-2)
      const hours = ('0' + date.getHours()).slice(-2)
      const minutes = ('0' + date.getMinutes()).slice(-2)
      const seconds = ('0' + date.getSeconds()).slice(-2)
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    },
    // 获取订单列表
    async getordersList () {
      const res = await ordersApi(this.obj)
      this.list = res.data.goods
      this.total = res.data.total
      console.log(res, '订单页面')
    },
    // 获取物流信息
    async getkuaidi (id) {
      const res = await kuaidiApi(id)
      this.kuaidi = res.data
      this.progressVisible = true
      console.log(res)
    },
    // 打开编辑对话框
    edit () {
      this.addressVisible = true
    },
    // 编辑确认
    queren () {

    },
    btn () {
      this.obj.query = this.value
      this.getordersList()
    }
  }
}
</script>
<style lang='less'  scoped>
.header {
  display: flex;
  margin-bottom: 20px;
  .input-with-select {
    width: 420px;
    margin-right: 15px;
  }
}
.actions {
  display: flex;
  button {
    display: flex;
    width: 43px;
    height: 28px;
    justify-content: center;
    align-items: center;
  }
}
.table {
  font-size: 12px;
}
.nav {
  font-size: 12px;
  margin-bottom: 15px;
}
</style>
